package com.nju.bean.string;

import java.util.Iterator;

import org.dom4j.*;

public class XmlHandler {
	private Document doc;
	
	public Document getDocument(){
		return doc;
	}
	
	public XmlHandler(String text)throws DocumentException{
		doc = XmlManager.getXML(text);
	}
	
	public String getAttribute(String ele,String att){
		Element root = doc.getRootElement();
		if(root.getName().equals(ele))
			return root.attribute(att).getText();
	    for ( Iterator i = root.elementIterator(ele); i.hasNext();) {
	        Element foo = (Element) i.next();
	        return foo.attribute(att).getText();
	     }
		return null;
	}
	
	public String getText(String ele){
		Element root = doc.getRootElement();
		if(root.getName().equals(ele))
			return root.getText();
	    for ( Iterator i = root.elementIterator(ele); i.hasNext();) {
	        Element foo = (Element) i.next();
	        return foo.getText();
	     }
		return null;
	}	
}
